package com.bwie.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.pojo.TbDict;
import com.bwie.service.TbDictService;
import com.bwie.mapper.TbDictMapper;
import com.bwie.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @author 31803
 * @description 针对表【tb_dict】的数据库操作Service实现
 * @createDate 2025-07-15 11:47:16
 */
@Service
public class TbDictServiceImpl extends ServiceImpl<TbDictMapper, TbDict>
        implements TbDictService {

    @Autowired
    TbDictMapper tbDictMapper;

    @Autowired
    StringRedisTemplate redisTemplate;

    @PostConstruct
    public void loaddictList() {
        List<TbDict> tbDictList = tbDictMapper.selectList(null);

        HashOperations<String, Object, Object> opsForHash = redisTemplate.opsForHash();
        for (TbDict tbDict : tbDictList) {
            String key1 = "dict-" + tbDict.getDictType();
            String key2 =  tbDict.getDictValue()+"";
            opsForHash.put(key1,key2,JSON.toJSONString(tbDict));
        }
    }

}




